app.controller('couponsDetailEditCtrl',['$scope','$state','$stateParams','toaster','couponsDetailEditService',function($scope,$state,$stateParams,toaster,couponsDetailEditService){

    $scope.couponsDetailEditService=couponsDetailEditService;
    $scope.id=$stateParams.id;
    couponsDetailEditService.coupons.id=$stateParams.id;

    $scope.findById=function(){
        couponsDetailEditService.findById($scope).then(function (result) {
            switch (result.status){
                case 200:
                    couponsDetailEditService.coupons=result.data;
                    break;
                case 640:
                    toaster.pop('waiting', "提示", result.message);
                    $state.go('app.404');
                    break;
                default :
                    break;
            }
        })
    }

    $scope.findById();

    $scope.editCoupons=function(){
        couponsDetailEditService.editCoupons($scope).then(function(result){
            switch (result.status){
                case 200:
                    toaster.pop('success', "提示", "操作成功");
                    $state.go('app.coupons');
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break;
            }
        })
    }



}]);